/**
 * File: MapEntryReader.java
 * Created by: mhaimel
 * Created on: 17 Aug 2009
 * CVS:  $Id: MapEntryReader.java,v 1.1 2009/08/27 14:52:44 mhaimel Exp $
 */
package uk.ac.ebi.curtain.util.io;

import java.io.BufferedReader;
import java.io.File;
import java.util.Iterator;

import uk.ac.ebi.curtain.utils.file.maq.MaqFlag;
import uk.ac.ebi.velvet.model.Strand;

/**
 * @author mhaimel
 *
 */
public class MapEntryReader extends AbstractReader<MapEntryBean> {

	public MapEntryReader(File in) {
		super(in);
	}
	
	@Override
	protected Iterator<MapEntryBean> _buildIter(File inFile) {
		return new MapEntryReaderIter(inFile);
	}

	public static class MapEntryReaderIter extends AbstractIter<MapEntryBean> {
		
		public MapEntryReaderIter(File f) {
			super(f);
		}
		public MapEntryReaderIter(File f, BufferedReader in) {
			super(f, in);
		}


		/* CtgID | ReadID | location | flagByte | Read Strand | AlignStrand | Category || mapQual | SemQual | AltQual*/
		@Override
		protected MapEntryBean _buildEntry(String[] arr) {
			MapEntryBean bean = new MapEntryBean();
			bean.setContigId(new String(arr[0]));
			bean.setReadId(new String(arr[1]));
			bean.setReferenceLocation(Integer.valueOf(arr[2]).intValue());
			bean.setFlag(MaqFlag.getFlag(Byte.valueOf(arr[3]).byteValue()));
			bean.setReadOrientation(Strand.getStrand(arr[4].charAt(0)));
			bean.setAlignOrientation(Strand.getStrand(arr[5].charAt(0)));
			bean.setCategory(Integer.valueOf(arr[6]));
			if(arr.length >9){
				bean.setMapQual(Integer.valueOf(arr[7]));
				bean.setSemQual(Integer.valueOf(arr[8]));
				bean.setAltQual(Integer.valueOf(arr[9]));
			}
			if(arr.length >11){
				bean.setAlignLength(Integer.valueOf(arr[10]));
				bean.setReadLocation(Integer.valueOf(arr[11]));
			}
			return bean;
		}
	}

}
